package com.rensanning.poi;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;

public abstract class AbstractSample {

	public Workbook readExcelFile(String filename) {
		FileInputStream in = null;
		Workbook wb = null;

		try {
			in = new FileInputStream(filename);
			wb = WorkbookFactory.create(in);			
		} catch (IOException e) {
			System.out.println(e.toString());
		} catch (InvalidFormatException e) {
			System.out.println(e.toString());
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				System.out.println(e.toString());
			}
		}
		
		return wb;
	}

	public void createExcelFile(Workbook wb, String filename) {
		FileOutputStream out = null;

		try {
			out = new FileOutputStream(filename);
			wb.write(out);		
		} catch (IOException e) {
			System.out.println(e.toString());
		} finally {
			try {
				out.close();
			} catch (IOException e) {
				System.out.println(e.toString());
			}
		}		
	}
	
}
